import 'package:flutterclue/mvp/presenter/base_presenter.dart';
import 'package:flutterclue/utils/SharePreferensUtil.dart';
import 'package:flutterclue/http_util/constant_url.dart';
import 'package:flutterclue/mvp/mode/MessageListBean.dart';

class MessagePagePresenter extends ClueBasePresenter<MessagePageView> {
  ///
  getMessageList({int pageIndex}) async {
    baseView.showLoadingView();
    Map<String, Object> map = new Map();
    map["AgentId"] =
        await SharePreferencesUtil.getString(SharePreferencesUtil.AgentId);
    map["TopAgentId"] =
        await SharePreferencesUtil.getString(SharePreferencesUtil.TopAgentId);
    map["PageSize"] = "15";
    map["PageIndex"] = "$pageIndex";
    await postData(
        url: ApiUrl.MessageList_URL,
        params: map,
        error: (error) {
          baseView.dismissLoadingView();
          baseView.onFail(error.toString() == null ? "" : error.toString());
        }).then((bean) {
      baseView.dismissLoadingView();
      if (bean.Code == 1) {
        MessageListBean messageListBean =
            new MessageListBean.fromJson(bean.Data);
        baseView.onSuccessMessageListBean(messageListBean);
      } else {
        baseView.onFail(bean.Message == null ? "" : bean.Message);
      }
    });
  }
}

abstract class MessagePageView extends BaseView {
  void onSuccessMessageListBean(MessageListBean messageListBean);

  void onFail(String message);
}
